<template>
  <div class="photoinfo">
    <van-panel
      :title="photoinfo.title"
      :status="'阅读'+photoinfo.click"
    >
      <div class="imgs-box">
        <img
          v-for="(item,index) in thumImages"
          :key="item.id"
          :src="item.src"
          alt=""
          @click="ImagePreview(index)"
        >
      </div>
      <!-- <div>{{newsinfo.content}}</div> -->
    </van-panel>
    <Comment :id="id"></Comment>
  </div>
</template>
<script>
import { ImagePreview } from 'vant'
import Comment from '../../../components/Comment'
import { getImageInfo, getThumimages } from '../../../api/photos'
export default {
  props: ['id'],
  data: () => ({
    photoinfo: {},
    thumImages: []
  }),
  methods: {
    async getImageInfo() {
      const res = await getImageInfo(this.id)
      this.photoinfo = res.data.message
    },
    async getThumimages() {
      const res = await getThumimages(this.id)
      this.thumImages = res.data.message
    },
    ImagePreview(startPosition) {
      const images = []
      this.thumImages.forEach(item => {
        if (item.src) {
          images.push(item.src)
        }
      })
      ImagePreview({
        images,
        startPosition
      })
    }
  },
  created() {
    this.getImageInfo()
    this.getThumimages()
  },
  components: { Comment }
}
</script>
<style lang="less" scoped>
.photoinfo {
  padding: 10px;
  .van-cell {
    font-weight: 600;
  }
  .van-panel__header-value {
    flex: 0.5;
  }
  .van-panel__content {
    font-size: 12px;
    text-indent: 2em;
  }
  .imgs-box {
    padding: 10px 0;
    display: flex;
    justify-content: space-between;
    img {
      width: 100px;
      height: 100px;
    }
  }
}
</style>
